package net.hn.hnms.biz.plan.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import net.hn.hnms.biz.plan.request.ExecutionWashingReq;
import net.hn.hnms.biz.plan.service.impl.ExecutionWashingServiceImpl;
import net.hn.hnms.biz.plan.vo.ExecutionWashingVO;
import net.hn.hnms.sys.common.core.domain.R;
import net.hn.hnms.sys.common.core.domain.ResponsePage;
import net.hn.hnms.sys.common.core.web.controller.BaseController;
import net.hn.hnms.sys.common.log.annotation.Log;
import net.hn.hnms.sys.common.log.enums.BusinessType;
import net.hn.hnms.sys.common.mybatis.core.page.PageQuery;
import net.hn.hnms.sys.common.satoken.config.AutoSetMineCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 洗选计划
 *
 * @author zhaoyang
 * @date 2022-08-01
 */

@Api(value = "洗选计划模块", tags = {"洗选计划"})
@RestController
@RequestMapping("/execution/washing")
public class ExecutionWashingController extends BaseController {


    @Autowired
    private ExecutionWashingServiceImpl executionWashingService;


    /**
     * 新增洗选计划
     */
    @ApiOperation("新增洗选计划")
    @SaCheckPermission("execution:washing:add")
    @PostMapping("/add")
    @Log(title = "新增洗选计划", businessType = BusinessType.INSERT)
    public R<Void> add(@Validated @RequestBody ExecutionWashingReq executionWashing) {

        return toAjax(executionWashingService.insert(executionWashing));
    }

    /**
     * 删除洗选计划
     */
    @ApiOperation("删除洗选计划")
    @SaCheckPermission("execution:washing:delete")
    @ApiImplicitParam(name = "idList", value = "要删除的id值,用逗号间隔", required = true, allowMultiple = true, dataType = "String", paramType = "query")
    @DeleteMapping("delete")
    @Log(title = "删除洗选计划", businessType = BusinessType.DELETE)
    public R<Void> delete(@RequestParam("idList") List<String> idList) {
        executionWashingService.deleteBatch(idList);
        return R.ok();
    }

    /**
     * 修改洗选计划
     */
    @ApiOperation("修改洗选计划")
    @SaCheckPermission("execution:washing:update")
    @PutMapping("/update")
    @Log(title = "修改洗选计划", businessType = BusinessType.UPDATE)
    public R<Void> update(@Validated @RequestBody ExecutionWashingReq executionWashing) {
        executionWashingService.updateById(executionWashing);
        return R.ok();
    }

    /**
     * 获取洗选计划列表
     */
    @ApiOperation("获取洗选计划分页列表")
//    @SaCheckPermission("execution:washing:page")
    @GetMapping("/page")
    @AutoSetMineCode
    public R<ResponsePage<ExecutionWashingVO>> page(ExecutionWashingReq executionWashing, PageQuery pageQuery) {
        return R.ok(executionWashingService.selectPageList(executionWashing, pageQuery));
    }

    /**
     * 获取洗选计划列表
     */
    @ApiOperation("获取洗选计划列表")
//    @SaCheckPermission("execution:washing:list")
    @GetMapping("/list")
    public R<List<ExecutionWashingVO>> list(ExecutionWashingReq executionWashing) {
        return R.ok(executionWashingService.selectList(executionWashing));
    }

    /**
     * 获取洗选计划详情
     */
    @ApiOperation("获取洗选计划详情")
//    @SaCheckPermission("execution:washing:list")
    @GetMapping("/{id}")
    public R<ExecutionWashingVO> detail(@PathVariable("id") String id) {
        return R.ok(executionWashingService.selectDetailById(id));
    }


}
